extends CanvasLayer

var pink_mon = preload("res://my_sprites/purple_mon/purple_mon.tscn")

func _ready() -> void:
	var new_pin_mon = pink_mon.instantiate()
	%Enemy.add_child(new_pin_mon)
	#待优化： 设计一个背包，把加载所有的DokiMons 改为只加载背包中的DokiMons
	for i in MySpriteData.SelectedDokiMons:
		var monTemp = MySpriteData.SelectedDokiMons[i]["Scene"].instantiate()
		monTemp.name = MySpriteData.SelectedDokiMons[i]["Name"]
		monTemp.hide()
		%Player.add_child(monTemp)
	%Player.get_child(0).show()
	
func MonsterTurn() -> void:
	var damage = randi_range(15,25)
	if %Enemy.get_child(0).Health <= 0:
		%BattleGroundUI.new_battle_victory_defeat.visible = true
		%BattleGroundUI.new_battle_victory_defeat.battle_result_button.text = "战斗胜利"
		Utils.save_game()
		MySpriteData.addEXP(10)
		get_tree().paused = false
		await get_tree().create_timer(2).timeout
		queue_free()
	%Player.get_child(%BattleGroundUI.selected).hit("Blast", damage)
	%BattleGroundUI.action.text = %Enemy.get_child(0).name + " attack " + str(damage) +" hp"
	MySpriteData.SelectedDokiMons[%BattleGroundUI.selected]["Health"] -= damage
	if MySpriteData.SelectedDokiMons[%BattleGroundUI.selected]["Health"] <= 0:
		%BattleGroundUI.new_battle_victory_defeat.visible = true
		%BattleGroundUI.new_battle_victory_defeat.battle_result_button.text = "战斗失败"
		Utils.save_game()
		await get_tree().create_timer(2).timeout
		queue_free()
		
		
	
	

